<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '新增供应商',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    <!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <script type="text/javascript">
        $(".js-sidebar-nav>li:nth-child(5)>a").addClass("active");
    </script>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper supplier">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">
                                <ol class="am-breadcrumb am-breadcrumb-slash">
                                    <li><a href="/admin/supplier/index?page=1">供应商管理</a></li>
                                    <li class="am-active">新增供应商</li>
                                </ol>
                            </div>
                        </div>
                        <form id="form" action="/admin/supplier/add" method="post" enctype="multipart/form-data"
                              class="am-form am-text-sm">
                            <div class="widget-body  am-fr">
                                <div class="tpl-table-black-operation">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        基本信息
                                    </a>
                                </div>

                                <div style="margin-top: 20px">
                                    <div class="am-g">
                                        <!-- Row start -->
                                        <div class="am-u-sm-12 am-g-fixed">
                                            <div class="am-u-md-6">
                                                <!--                                                    <form class="am-form am-text-sm">-->
                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="code">供应商编号</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="code"
                                                               value="<?php echo 'GYS' . date('Ymd') . rand(100, 999) ?>"
                                                               id="code" readonly>
                                                    </div>

                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                           for="supplierUser">供应商账号</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="supplierUser"
                                                               id="supplierUser">
                                                    </div>

                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="linkMan">联系人</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="linkMan"
                                                               id="linkMan">
                                                    </div>


                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must">公司地址</label>
                                                    <div id="distpicker" class="am-u-md-10">
																								        <select class="form-control" id="province" name="province" data-am-selected="{btnWidth: '32%',maxHeight: 200}"></select>
																								        <select class="form-control" id="city" name="city" data-am-selected="{btnWidth: '32%',maxHeight: 200}"></select>
																								        <select class="form-control" id="district" name="district" data-am-selected="{btnWidth: '32%',maxHeight: 200}"></select>
																								    </div>
																								    <div class="am-u-md-10 am-margin-vertical-sm">
																								    		<input type="text" name="address" id="address" value="" placeholder="详细地址" />
																								    </div>
                                                </div>
                                                <!--                                                    </form>-->
                                            </div>

                                            <div class="am-u-md-6">
                                                <!--                                                    <form class="am-form am-text-sm">-->
                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="name">供应商名称</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="name" id="name">
                                                    </div>
                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                           for="supplierPass">密码</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="supplierPass"
                                                               id="supplierPass">
                                                    </div>
                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="phone">联系电话</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="phone"
                                                               id="phone">
                                                    </div>
                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                           for="type">供应商类型</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="type"  id="type">
                                                    </div>
                                                </div>

                                                <!--                                                    </form>-->
                                            </div>
                                        </div>
                                        <!-- Row end -->
                                    </div>
                                    <hr>
                                </div>

                                <div class="tpl-table-black-operation">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        账户信息
                                    </a>
                                </div>

                                <div style="margin-top: 20px" class=" am-g-fixed">
                                    <div class="am-g">
                                        <div class="am-u-sm-6">
                                            <div class="am-form-group am-u-sm-12">
                                                <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                       for="bank">开户银行</label>
                                                <div class="am-u-md-10">
                                                    <input type="text" name="bank" id="bank">
                                                </div>
                                            </div>
                                            <div class="am-u-md-12 am-form-group">
                                                    <!--                                                    <form class="am-form am-text-sm">-->
                                                        <div class="am-form-file">
                                                            <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                                   for="generateSeal">公司章印</label>
                                                            <div class="am-u-md-5">
                                                                <button type="button" class="am-btn am-btn-default am-btn-sm">
                                                                    <i class="am-icon-cloud-upload"></i> 选择要上传的文件
                                                                </button>
                                                                <input type="file" accept="image/png,image/jpeg" class="am-u-md-2 form-control" name="generateSeal" value=""
                                                               id="generateSeal">
                                                                <div class="file-show">
                                                                </div>
                                                            </div>
                                                            <div class="am-u-md-5"><img src="" alt="公司章印" class="see-img am-img-responsive am-img-thumbnail am-radius" onerror="this.onerror=null;this.src='/assets/img/default.jpg'" ></div>
                                                        </div>

                                                    <div class="zhushi">
                                                        注：底色透明,不超过20K
                                                    </div>
                                                </div>
                                        </div>
                                        <div class="am-u-sm-6">
                                            <div class="am-form-group  am-u-sm-12">
                                                <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                       for="bankAccount">银行账户</label>
                                                <div class="am-u-md-10">
                                                    <input type="text" name="bankAccount" value=""
                                                           id="bankAccount">
                                                </div>


                                            </div>

                                            <div class="am-form-group am-u-sm-12">
                                                <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                       for="registerNo">统一社会信用代码</label>
                                                <div class="am-u-md-10">
                                                    <input type="text" name="registerNo" value=""
                                                           id="registerNo">
                                                </div>

                                            </div>
                                        </div>

                                    </div>
                                </div>


                                <div class="tpl-table-black-operation">
                                    <hr/>

                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        更多信息
                                    </a>
                                </div>

                                <div style="margin-top: 20px">
                                    <div class="am-g">
                                        <!-- Row start -->
                                        <div class="am-u-sm-12 am-g-fixed">
                                            <div class="am-g">
                                                <div class="am-u-md-6">
                                                    <!--                                                    <form class="am-form am-text-sm">-->
                                                    <div class="am-form-group  am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="createTime">成立时间</label>
                                                        <div class="am-u-md-10">
                                                            <input type="text" class="am-form-field"
                                                                   placeholder="选择成立时间" data-am-datepicker readonly
                                                                   name="createTime" id="createTime"/>
                                                        </div>

                                                    </div>

                                                    <div class="am-form-group am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="nature">公司性质</label>
                                                        <div class="am-u-md-10">
                                                            <!-- <input type="text" name="nature"
                                                                   id="nature"> -->
                                                            <select name="nature" id="nature" data-am-selected="{btnWidth: '100%',maxHeight: 200}">
                                                                <option value=""></option>
                                                                <option value="国有企业">国有企业</option>
                                                                <option value="集体企业">集体企业</option>
                                                                <option value="联营企业">联营企业</option>
                                                                <option value="股份合作制企业">股份合作制企业</option>
                                                                <option value="私营企业">私营企业</option>
                                                                <option value="个体户">个体户</option>
                                                                <option value="合伙企业">合伙企业</option>
                                                                <option value="有限责任公司">有限责任公司</option>
                                                                <option value="股份有限公司">股份有限公司</option>
                                                            </select>
                                                        </div>

                                                    </div>

                                                    <div class="am-form-group am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="vender">外包厂商</label>
                                                        <!-- <input class=" form-control" name="vender"
                                                               id="vender"> -->
                                                        <div class="am-input-group am-u-md-10">
                                                            <input type="number" class="am-form-field" name="vender"
                                                                   id="vender">
                                                            <span class="am-input-group-label">家</span>
                                                        </div>
                                                    </div>

                                                    <div class="am-form-group am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="note">备注</label>
                                                        <div class="am-u-md-10">
                                                            <textarea class="am-u-md-10 form-control" rows="5"
                                                                      name="note" id="note"></textarea>
                                                        </div>

                                                    </div>
                                                    <!--                                                    </form>-->
                                                </div>

                                                <div class="am-u-md-6">
                                                    <!--                                                    <form class="am-form am-text-sm">-->
                                                    <div class="am-form-group  am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="size">公司规模</label>
                                                        <div class="am-u-md-10">
                                                            <!-- <input type="text" name="size" value=""
                                                                   id="size"> -->
                                                            <select name="size" id="size" data-am-selected="{btnWidth: '100%',maxHeight: 200}">
                                                                <option value=""></option>
                                                                <option value="0-99人">0-99人</option>
                                                                <option value="100-499人">100-499人</option>
                                                                <option value="500-999人">500-999人</option>
                                                                <option value="1000-9999人">1000-9999人</option>
                                                                <option value="10000人以上">10000人以上</option>
                                                            </select>
                                                        </div>

                                                    </div>

                                                    <div class="am-form-group am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="isProducers">是否为生产者</label>
                                                        <div class="am-form-group am-u-md-10">
                                                            <label class="am-radio-inline">
                                                                <input type="radio" name="isProducers" value="1"
                                                                       checked>
                                                                是
                                                            </label>
                                                            <label class="am-radio-inline">
                                                                <input type="radio" name="isProducers" value="0">
                                                                否
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="am-form-group am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0 "
                                                               for="mail">公司邮箱</label>
                                                        <div class="am-u-md-10">
                                                            <input type="text" name="mail"
                                                                   id="mail">
                                                        </div>

                                                    </div>

                                                    <!--                                                    </form>-->
                                                </div>
                                            </div>
                                        </div>
                                        <!-- Row end -->
                                    </div>
                                </div>

                                <div class="btn-box">
                                    <input type="submit" class="am-btn am-btn-primary tpl-btn-bg-color-success "
                                           style="width:220px;margin: 20px;">
                                    <button onclick="back()" type="button"
                                            class="am-btn am-btn-primary tpl-btn-bg-color-success " style="width:220px">
                                        取消
                                    </button>
                                </div>

                            </div>


                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function back() {
        window.history.back();
    }
</script>

<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/distpicker.data.js"></script>
<script src="/assets/js/distpicker.js"></script>
<script src="/assets/js/zdy_form.js"></script>

<script type="text/javascript">
	  $('#distpicker').distpicker({
	    autoSelect: false
	  });
	  
    $("#generateSeal").change(function (event) {
        
        var files = event.target.files, file;
        if (files && files.length > 0) {
            // 获取目前上传的文件
            file = files[0];

            if (file.size > 1024 * 20) {
                alert('图片大小不能超过 20K!');
                return false;
            }
            var URL = window.URL || window.webkitURL;
            // 通过 file 生成目标 url
            var imgURL = URL.createObjectURL(file);
            // 用这个 URL 产生一个 <img> 将其显示出来
            $(".see-img").attr('src', imgURL);
            // 使用下面这句可以在内存中释放对此 url 的伺服，跑了之后那个 URL 就无效了
            // URL.revokeObjectURL(imgURL);
        }else{
            $(".see-img").attr('src', "");
        }

        var filePath = $(this).val();
        if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1){
            var arr = filePath.split('\\');
            var fileName = arr[arr.length-1];
            $(".file-show").html(fileName);
        }else{
            $(".file-show").html("");
            return false;
        }
        
    });

    var lockSubmit = false;

    $("#form").submit(function () {
        if(lockSubmit){
            return false;
        }

        lockSubmit =true;
        // 表单验证
        var valid = zdy.validate.valid({
            rules: {
                code: {required: true},
                name: {required: true},
                linkMan: {required: true},
                phone: {required: true, isMobile: true},
                province: {required: true},
                city: {required: true},
                address: {required: true},
                bank: {required: true},
                bankAccount: {required: true},
                generateSeal: {required: true},
                registerNo: {required: true}
            }, message: {
                code: {required: "供应商编号不能为空"},
                name: {required: "请填写供应商名称"},
                linkMan: {required: "请填写联系人"},
                phone: {required: "请填写联系电话", isMobile: "请填写有效的11位手机号。"},
                province: {required: "请选择公司地址"},
                city: {required: "请选择公司地址"},
                address: {required: "请填写公司地址"},
                bank: {required: "请填写开户银行"},
                bankAccount: {required: "请填写银行账户"},
                generateSeal: {required: "请上传公司章印"},
                registerNo: {required: "请填写统一社会信用代码"}

            }
        });
        if (!valid) {
            lockSubmit  = false;
            return false;
        }
    });
</script>

</body>

</html>